package actions;

import bin.Mud;
import mobs.NPC;

public class CombatDecider {
    private Mud mudWindow;

    public CombatDecider(Mud mudWindow) {
        this.mudWindow = mudWindow;
    }

    public boolean isAttack() {
        String attack = mudWindow.getCommand();
        return (attack.startsWith("K ") || attack.startsWith("KILL "));
    }

    public boolean isFlee() {
        String command = mudWindow.getCommand();
        return (command.equals("FLEE"));
    }

    public boolean isValidMob() {
        String command = mudWindow.getCommand().replaceFirst("K ", "").replaceFirst("KILL ", "");
        for (NPC mob : mudWindow.getRoom().getActiveNPCs()) {
            if (command.equalsIgnoreCase(mob.getName()) || command.equalsIgnoreCase(mob.getShortName())) {
                return true;
            }
        }
        return false;
    }

    public NPC getMobToAttack() {
        String command = mudWindow.getCommand().replaceFirst("K ", "").replaceFirst("KILL ", "");
        for (NPC mob : mudWindow.getRoom().getActiveNPCs()) {
            if (command.equalsIgnoreCase(mob.getName()) || command.equalsIgnoreCase(mob.getShortName())) {
                return mob;
            }
        }
        return null;
    }
}
